package com.chandra.pos.payment.dao;

import com.chandra.pos.payment.dao.entity.PaymentEntity;
import com.chandra.pos.payment.dao.entity.PaymentMethod;
import com.chandra.pos.payment.dao.entity.PaymentStatus;
import org.joda.time.DateTime;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by Admin on 8/14/14.
 */
@Transactional(readOnly = true)
public interface PaymentRepository extends JpaRepository<PaymentEntity, Long> {


    @Query("SELECT p FROM PaymentEntity p WHERE p.paymentMethod = :paymentMethod and  p.paymentDate between :startDate and :endDate")
    public Page<PaymentEntity> searchPayments1(@Param("paymentMethod") PaymentMethod paymentMethod, @Param("startDate") DateTime startDate, @Param("endDate") DateTime endDate, Pageable pageable);


    @Query("SELECT p FROM PaymentEntity p WHERE p.paymentMethod = :paymentMethod and  p.paymentStatus = :paymentStatus and  p.paymentDate between :startDate and :endDate")
    public Page<PaymentEntity> searchPayments2(@Param("paymentMethod") PaymentMethod paymentMethod, @Param("paymentStatus") PaymentStatus paymentStatus, @Param("startDate") DateTime startDate, @Param("paymentMethod") DateTime endDate, Pageable pageable);


    Page<PaymentEntity> findByPaymentDateBetween(DateTime startDate, DateTime endDate, Pageable request);
}
